package com.yanghui.dtracing.plugin.springmvc;

import com.yanghui.dtracing.core.match.ClassMatch;
import com.yanghui.dtracing.core.match.NameMatch;
import com.yanghui.dtracing.core.plugin.AbstractClassEnhancePluginDefine;
import com.yanghui.dtracing.core.plugin.IInstanceMethodInterceptPoint;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;

public class SpringMvcDefinition extends AbstractClassEnhancePluginDefine {

    @Override
    public ClassMatch enhanceClass() {
        return new NameMatch("org.springframework.web.servlet.DispatcherServlet");
    }

    @Override
    public IInstanceMethodInterceptPoint[] buildInstanceMethodInterceptPoints() {
        return new IInstanceMethodInterceptPoint[]{
            new IInstanceMethodInterceptPoint(){
                @Override
                public boolean isOverrideArgs() {
                    return true;
                }

                @Override
                public ElementMatcher<MethodDescription> buildMethodsMatcher() {
                    return ElementMatchers.named("doDispatch");
                }
                @Override
                public String methodInterceptor() {
                    return "com.yanghui.dtracing.plugin.springmvc.SpringMvcMethodAroundInterceptor";
                }
            }
        };
    }
}
